﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MatchCore
{
    public struct Vector2
    {
        public int x;
        public int y;

        public Vector2(int x,int y)
        {
            this.x = x;
            this.y = y;
        }

        public static Vector2 operator+(Vector2 v1, Vector2 v2)
        {
            return new Vector2(v1.x + v2.x,v1.y + v2.y);
        }

        public bool Equals(Vector2 other)
        {
            return this.x == other.x && this.y == other.y;
        }
    }

    public struct Rect
    {
        public int x;
        public int y;
        private int _width;
        private int _height;

        public int width
        {
            get
            {
                return _width;
            }
        }

        public int height
        {
            get
            {
                return _height;
            }
        }

        public Vector2 center
        {
            get
            {
                return new Vector2(x + (_width / 2),y + (_height / 2));
            }
            set
            {
                x = value.x - (_width / 2);
                y = value.y - (_height / 2);
            }
        }

        public int left
        {
            get
            {
                return this.x;
            }
            set
            {
                this.x = value;
            }
        }

        public int right
        {
            get
            {
                return this.x + this._width;
            }
            set
            {
                this.x = value - this._width;
            }
        }

        public int top
        {
            get
            {
                return this.y;
            }
            set
            {
                this.y = value;
            }
        }

        public int bottom
        {
            get
            {
                return this.y + this._height;
            }
            set
            {
                this.y = value - this._height;
            }
        }

        public Rect(int x,int y,int width,int height)
        {
            this.x = x;
            this.y = y;
            this._width = width;
            this._height = height;
        }

        public void SetSize(int width,int height)
        {
            if(width < 0 || height < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            this._width = width;
            this._height = height;
        }

        public bool Contains(Vector2 point)
        {
            return Contains(point.x, point.y);
        }

        public bool Contains(int x,int y)
        {
            if(x >= this.left && x <= this.right
                && y >= this.top && y <= this.bottom)
            {
                return true;
            }

            return false;
        }

        public bool Contains(Rect other)
        {
            if(other.left >= this.left && other.right <= this.right
                && other.top >= this.top && other.bottom <= this.bottom)
            {
                return true;
            }
            return false;
        }
    }

    public class Utils
    {

    }
}
